//Replication data for Shelef, Nadav; Jamison, Anne, 2024, "Replication Data for: Domestic legitimacy, coethnics abroad, and the shape of the homeland", https://doi.org/10.7910/DVN/FWK7IN, Harvard Dataverse

//This do-file replicates all graphs in the body of the paper. The code for the tables can be found in a separate do-file. 

//Computed on Stata 17.0 SE

//load data
use "cox data.dta"

//all graphs below require this preamble: 

stset time if potato_any_ModifiedEPR ==1 & colony==0, failure(homeland) exit(time .) origin(time0_minus1) id(id)


stsplit, at(failure)
replace mid_current_tvc= mid_current*ln(_t)
replace priormid_tvc= priormid*ln(_t)
replace coethnic_presence_tek_mod_tvc= coethnic_presence_tek_mod*ln(_t)
replace poly_binary_dem1other0_tvc= poly_binary_dem1other0*ln(_t)
replace econ_value_all_tvc= econ_value_all*ln(_t) 
replace cincrat_updtd_clclpwr_tvc= cincrat_updtd_clclpwr *ln(_t)
replace capital_distance_ln_tvc= capital_distance_ln*ln(_t)
replace global_qtile_tvc= global_qtile*ln(_t)
replace strata2_tvc= strata2*ln(_t)
replace strata3_tvc=  strata3*ln(_t)
replace strata4up_tvc=  strata4up*ln(_t)
replace regimeage_Vdem_tvc= regimeage_Vdem*ln(_t)
replace coethnicXdemocracy_tvc=coethnicXdemocracy*ln(_t)



***********
***********
//Figure 1: Risk of societal applications of homeland territoriality to lost lands with coethnics (Cox conditional hazard)
***********
***********


//(a) Regime type

stcox mid_current priormid i.coethnic_presence_tek##i.poly_binary_dem1other0 econ_value_all cincrat_updtd_clclpwr capital_distance_ln global_qtile strata2 strata3 strata4up regimeage_Vdem , shared(id) forceshared efron
estat phtest, rank detail

**TVC needed (.1): priormid coethnic_presence_tek econ_value_all cincrat_updtd_clclpwr capital_distance_ln global_qtile regimeage_Vdem strata2 strata3 strata4up

stcox mid_current priormid i.coethnic_presence_tek_mod##i.poly_binary_dem1other0 econ_value_all cincrat_updtd_clclpwr capital_distance_ln global_qtile strata2 strata3 strata4up regimeage_Vdem priormid_tvc econ_value_all_tvc capital_distance_ln_tvc regimeage_Vdem_tvc  strata2_tvc strata3_tvc strata4up_tvc, shared(id) forceshared efron

stcurve, hazard at1(coethnic_presence_tek_mod=1 poly_binary_dem1other0=0) at2(coethnic_presence_tek_mod=1 poly_binary_dem1other0=1)  legend(label(1 "Autocratic society," "Coethnics") label(2 "Democratic society," "Coethnics")) xtitle("analysis time (years)") lwidth(thick thick) lcolor(black black) lpattern(solid dash ) graphregion(color(white)) bgcolor(white)
** manually got rid of grid lines, stata generated titles, and shifted y axis title -1

//(b) Proportion of (log) population belonging to excluded ethnic groups

stcox mid_current priormid i.coethnic_presence_tek_mod##c.ln_losingstate_exclpop econ_value_all cincrat_updtd_clclpwr capital_distance_ln global_qtile strata2 strata3 strata4up regimeage_Vdem, shared(id) forceshared efron
estat phtest, rank detail

*TVC needed: priormid econ_value_all capital_distance_ln regimeage_Vdem  strata2 strata3 strata4up

stcox mid_current priormid i.coethnic_presence_tek_mod##c.ln_losingstate_exclpop econ_value_all cincrat_updtd_clclpwr capital_distance_ln global_qtile strata2 strata3 strata4up regimeage_Vdem, tvc(priormid econ_value_all capital_distance_ln regimeage_Vdem  strata2 strata3 strata4up) texp(ln(_t)) shared(id) forceshared efron

*after stsplit:
stcox mid_current priormid i.coethnic_presence_tek_mod##c.ln_losingstate_exclpop econ_value_all cincrat_updtd_clclpwr capital_distance_ln global_qtile strata2 strata3 strata4up regimeage_Vdem priormid_tvc econ_value_all_tvc capital_distance_ln_tvc regimeage_Vdem_tvc  strata2_tvc strata3_tvc strata4up_tvc, shared(id) forceshared efron

stcurve, hazard at1(coethnic_presence_tek_mod=1 ln_losingstate_exclpop==-.579818) at2(coethnic_presence_tek_mod=1 ln_losingstate_exclpop==-27.631)   legend(label(1 "90{superscript:th} percentile of population" "excluded, Coethnics") label(2 "10{superscript:th} percentile of population" "excluded, Coethnics")) xtitle("analysis time (years)") lwidth(thick thick) lcolor(black black) lpattern(solid dash ) graphregion(color(white)) bgcolor(white)
** manually got rid of grid lines, stata generated titles, and shifted y axis title -1

//(c) GDP growth rate

stcox mid_current priormid i.coethnic_presence_tek_mod##c.gdpgrowth100 econ_value_all cincrat_updtd_clclpwr capital_distance_ln global_qtile strata2 strata3 strata4up regimeage_Vdem, shared(id) forceshared efron
estat phtest, rank detail

*TVC needed: regimeage_Vdem  strata2 strata3 strata4up

*after stsplit
stcox mid_current priormid i.coethnic_presence_tek_mod##c.gdpgrowth100 econ_value_all cincrat_updtd_clclpwr capital_distance_ln global_qtile strata2 strata3 strata4up regimeage_Vdem regimeage_Vdem_tvc  strata2_tvc strata3_tvc strata4up_tvc, shared(id) forceshared efron

stcurve, hazard at1(coethnic_presence_tek_mod=1 gdpgrowth100 =-9) at2(coethnic_presence_tek_mod=1 gdpgrowth100 =8)   legend(label(1 "Low GDP Growth" "(10{superscript:th} percentile)," "Coethnics") label(2 "High GDP Growth" "(90{superscript:th} percentile)," "Coethnics")) xtitle("analysis time (years)") lwidth(thick thick thick thick) lpattern(solid dash longdash shortdash) lcolor(black black gray gray) graphregion(color(white)) bgcolor(white)


***********
***********
//Figure 2: Risk of applying homeland territoriality in contexts likely to rely on ethnic legitimization, by whether that land has coethnics (Cox conditional hazard)
***********
***********

//(a) Authoritarian regimes 

stcox mid_current priormid i.coethnic_presence_tek##i.poly_binary_dem1other0 econ_value_all cincrat_updtd_clclpwr capital_distance_ln global_qtile strata2 strata3 strata4up regimeage_Vdem , shared(id) forceshared efron
estat phtest, rank detail

**TVC needed (.1): priormid coethnic_presence_tek econ_value_all cincrat_updtd_clclpwr capital_distance_ln global_qtile regimeage_Vdem strata2 strata3 strata4up

stcox mid_current priormid i.coethnic_presence_tek_mod##i.poly_binary_dem1other0 econ_value_all cincrat_updtd_clclpwr capital_distance_ln global_qtile strata2 strata3 strata4up regimeage_Vdem priormid_tvc econ_value_all_tvc capital_distance_ln_tvc regimeage_Vdem_tvc  strata2_tvc strata3_tvc strata4up_tvc, shared(id) forceshared efron

stcurve, hazard at2(coethnic_presence_tek_mod=0 poly_binary_dem1other0=0) at1(coethnic_presence_tek_mod=1 poly_binary_dem1other0=0)  legend(label(2 "Autocratic society," "No coethnics") label(1 "Autocratic society," "Coethnics")) xtitle("analysis time (years)") lwidth(thick thick) lcolor(black black) lpattern(solid dash ) graphregion(color(white)) bgcolor(white)

//(b) 90th percentile of (log) population belonging to excluded ethnic groups 

stcox mid_current priormid i.coethnic_presence_tek_mod##c.ln_losingstate_exclpop econ_value_all cincrat_updtd_clclpwr capital_distance_ln global_qtile strata2 strata3 strata4up regimeage_Vdem, shared(id) forceshared efron
estat phtest, rank detail

*TVC needed: priormid econ_value_all capital_distance_ln regimeage_Vdem  strata2 strata3 strata4up

stcox mid_current priormid i.coethnic_presence_tek_mod##c.ln_losingstate_exclpop econ_value_all cincrat_updtd_clclpwr capital_distance_ln global_qtile strata2 strata3 strata4up regimeage_Vdem, tvc(priormid econ_value_all capital_distance_ln regimeage_Vdem  strata2 strata3 strata4up) texp(ln(_t)) shared(id) forceshared efron

*after stsplit:
stcox mid_current priormid i.coethnic_presence_tek_mod##c.ln_losingstate_exclpop econ_value_all cincrat_updtd_clclpwr capital_distance_ln global_qtile strata2 strata3 strata4up regimeage_Vdem priormid_tvc econ_value_all_tvc capital_distance_ln_tvc regimeage_Vdem_tvc  strata2_tvc strata3_tvc strata4up_tvc, shared(id) forceshared efron

stcurve, hazard at1(coethnic_presence_tek_mod=1 ln_losingstate_exclpop==-.579818) at2(coethnic_presence_tek_mod=0 ln_losingstate_exclpop==-.579818)   legend(label(1 "90{superscript:th} percentile of population" "excluded, Coethnics") label(2 "90{superscript:th} percentile of population" "excluded, No coethnics")) xtitle("analysis time (years)") lwidth(thick thick) lcolor(black black) lpattern(solid dash ) graphregion(color(white)) bgcolor(white) ylabel(,nogrid)
** manually got rid of grid lines, stata generated titles, and shifted y axis title -1

//(c) Low GDP growth

stcox mid_current priormid i.coethnic_presence_tek_mod##c.gdpgrowth100 econ_value_all cincrat_updtd_clclpwr capital_distance_ln global_qtile strata2 strata3 strata4up regimeage_Vdem, shared(id) forceshared efron
estat phtest, rank detail

*TVC needed: regimeage_Vdem  strata2 strata3 strata4up

stcox mid_current priormid i.coethnic_presence_tek_mod##c.gdpgrowth100 econ_value_all cincrat_updtd_clclpwr capital_distance_ln global_qtile strata2 strata3 strata4up regimeage_Vdem regimeage_Vdem_tvc  strata2_tvc strata3_tvc strata4up_tvc, shared(id) forceshared efron

stcurve, hazard at1(coethnic_presence_tek_mod=1 gdpgrowth100=-9) at2(coethnic_presence_tek_mod=0 gdpgrowth100=-9)   legend(label(1 "Low GDP Growth" "(10{superscript:th} percentile)," "Coethnics") label(2 "Low GDP Growth" "(10{superscript:th} percentile)," "No coethnics")) xtitle("analysis time (years)") lwidth(thick thick thick thick) lpattern(solid dash longdash shortdash) lcolor(black black gray gray) graphregion(color(white)) bgcolor(white) ylabel(,nogrid)
*Manually got rid of Stata generated titles and shifted y axis title -1

***********
***********
//Figure 3: Risk of applying homeland territoriality to lost lands (Cox conditional hazard), combined
***********
***********

*Model in split dataset to generate graph

stcox mid_current priormid i.coethnic_presence_tek_mod##i.poly_binary_dem1other0 econ_value_all cincrat_updtd_clclpwr capital_distance_ln global_qtile strata2 strata3 strata4up regimeage_Vdem priormid_tvc econ_value_all_tvc capital_distance_ln_tvc regimeage_Vdem_tvc  strata2_tvc strata3_tvc strata4up_tvc, shared(id) forceshared efron

stcurve, hazard at1(coethnic_presence_tek_mod=1 poly_binary_dem1other0=0) at2(coethnic_presence_tek_mod=0 poly_binary_dem1other0=0) at3(coethnic_presence_tek_mod=1 poly_binary_dem1other0=1) at4(coethnic_presence_tek_mod=0 poly_binary_dem1other0=1)  legend(label(1 "Autocratic society," "coethnics") label(2 "Autocratic society," "no coethnics")label(3 "Democratic society," "coethnics")label(4 "Democratic society," "no coethnics")) xtitle("analysis time (years)") lwidth(thick thick thick thick) lpattern(solid longdash solid longdash) lcolor(black black gray gray) graphregion(color(white)) bgcolor(white)
*Manually got rid of grid lines, stata generated titles, and shifted y axis title -1



